package com.example.demo.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.entity.Storage;
import com.example.demo.service.StorageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 库存表(Storage)表控制层
 *
 * @author ElonChung
 * @since 2020-05-13 16:59:31
 */
@RestController
@RequestMapping("storage")
@Api(tags = "库存表(Storage)")
public class StorageController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private StorageService storageService;

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param storage 查询实体
     * @return 所有数据
     */
    @GetMapping("findAll")
    @ApiOperation(value = "分页查询所有数据 库存表")
    public R selectAll(Page<Storage> page, Storage storage) {
        logger.error("11111");
        return success(this.storageService.page(page, new QueryWrapper<>(storage)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("getOne/{id}")
    @ApiOperation(value = "通过主键查询单条数据 库存表")
    public R selectOne(@PathVariable Integer id) {
        return success(this.storageService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param storage 实体对象
     * @return 新增结果
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增数据 库存表")
    public R insert(@RequestBody Storage storage) {
        return success(this.storageService.save(storage));
    }

    /**
     * 修改数据
     *
     * @param storage 实体对象
     * @return 修改结果
     */
    @PutMapping("update")
    @ApiOperation(value = "修改数据 库存表")
    public R update(@RequestBody Storage storage) {
        return success(this.storageService.updateById(storage));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping("delete")
    public R delete(@RequestParam("idList") List<Long> idList) {
        return success(this.storageService.removeByIds(idList));
    }
}